/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nm;

import analysis.Analytic;
import core.Constants;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import methods.KrankaNikolsona;
import methods.NeYavnaya;
import methods.Yavnaya;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author Alexey Chirkov
 */
public class MainForm extends javax.swing.JFrame {

    /**
     * Creates new form MainForm
     */
    public MainForm() {
        initComponents();
        Draw();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupFixed = new javax.swing.ButtonGroup();
        buttonGroupMethod = new javax.swing.ButtonGroup();
        textSourceData = new javax.swing.JLabel();
        textThickness = new javax.swing.JLabel();
        valueThickness = new javax.swing.JTextField();
        textRadius = new javax.swing.JLabel();
        valueRadius = new javax.swing.JTextField();
        textBetta = new javax.swing.JLabel();
        valueBetta = new javax.swing.JTextField();
        textK = new javax.swing.JLabel();
        valueK = new javax.swing.JTextField();
        textC = new javax.swing.JLabel();
        valueC = new javax.swing.JTextField();
        textAlpha = new javax.swing.JLabel();
        valueAlpha = new javax.swing.JTextField();
        textU0 = new javax.swing.JLabel();
        valueU0 = new javax.swing.JTextField();
        textTimeEnd = new javax.swing.JLabel();
        valueTimeEnd = new javax.swing.JTextField();
        textP = new javax.swing.JLabel();
        valueP = new javax.swing.JTextField();
        sliderTime = new javax.swing.JSlider();
        sliderR = new javax.swing.JSlider();
        radioButtonR = new javax.swing.JRadioButton();
        radioButtonT = new javax.swing.JRadioButton();
        jPanel1 = new javax.swing.JPanel();
        valueMethodI = new javax.swing.JTextField();
        textMethod = new javax.swing.JLabel();
        textMethodI = new javax.swing.JLabel();
        textMethodK = new javax.swing.JLabel();
        valueMethodK = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        checkBoxMethod1 = new javax.swing.JCheckBox();
        checkBoxMethod2 = new javax.swing.JCheckBox();
        checkBoxMethod3 = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Курсовой проект по Численным методам");
        setResizable(false);

        textSourceData.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        textSourceData.setText("Исходные данные:");

        textThickness.setText("Толщина пластины");

        valueThickness.setText(Double.valueOf(core.Constants.getL()).toString());

        textRadius.setText("Радиус пластины");

        valueRadius.setText(Double.valueOf(core.Constants.getRadius()).toString());

        textBetta.setText("Коофицент поглощения");

        valueBetta.setText(Double.valueOf(core.Constants.getBetta()).toString());

        textK.setText("Коофицент теплопроводности");

        valueK.setText(Double.valueOf(core.Constants.getK()).toString());

        textC.setText("Теплоемкость");

        valueC.setText(Double.valueOf(core.Constants.getC()).toString());

        textAlpha.setText("Коофицент теплоотвода");

        valueAlpha.setText(Double.valueOf(core.Constants.getAlpha()).toString());

        textU0.setText("Начальная температура");

        valueU0.setText(Double.valueOf(core.Constants.getU0()).toString());

        textTimeEnd.setText("Конечное время");

        valueTimeEnd.setText(Double.valueOf(core.Constants.getTimeEnd()).toString());

        textP.setText("Мощность излучения");

        valueP.setText(Double.valueOf(core.Constants.getP()).toString());

        sliderTime.setMaximum(Yavnaya.getInstance().getK());
        sliderTime.setValue(0);
        sliderTime.setEnabled(false);
        sliderTime.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderTimeStateChanged(evt);
            }
        });

        sliderR.setMaximum(Yavnaya.getInstance().getI());
        sliderR.setValue(0);
        sliderR.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderRStateChanged(evt);
            }
        });

        buttonGroupFixed.add(radioButtonR);
        radioButtonR.setSelected(true);
        radioButtonR.setText("по r");
        radioButtonR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioButtonRActionPerformed(evt);
            }
        });

        buttonGroupFixed.add(radioButtonT);
        radioButtonT.setText("по t");
        radioButtonT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioButtonTActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 480, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 496, Short.MAX_VALUE)
        );

        valueMethodI.setText(Integer.toString(Yavnaya.getInstance().getI()));

        textMethod.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        textMethod.setText("Разностные схемы");

        textMethodI.setText("I=");

        textMethodK.setText("K=");

        valueMethodK.setText(Integer.toString(Yavnaya.getInstance().getK()));
        valueMethodK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                valueMethodKActionPerformed(evt);
            }
        });

        jButton1.setText("Применить");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        checkBoxMethod1.setText("Явная разностная хема");
        checkBoxMethod1.setEnabled(false);
        checkBoxMethod1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBoxMethod1ActionPerformed(evt);
            }
        });

        checkBoxMethod2.setText("Неявная разностная схема");
        checkBoxMethod2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBoxMethod2ActionPerformed(evt);
            }
        });

        checkBoxMethod3.setText("Разностная схемы Кранка-Николсона");
        checkBoxMethod3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBoxMethod3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textSourceData, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(textBetta)
                                            .addGap(52, 52, 52))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(textThickness, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(textRadius))
                                            .addGap(18, 18, 18)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(textC)
                                            .addComponent(textAlpha)
                                            .addComponent(textU0)
                                            .addComponent(textTimeEnd)
                                            .addComponent(textP)
                                            .addComponent(textK))
                                        .addGap(55, 55, 55)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(valueThickness, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                                    .addComponent(valueRadius, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(valueBetta, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(valueK, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(valueC, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(valueAlpha, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(valueU0, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(valueTimeEnd, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)
                                    .addComponent(valueP, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)))
                            .addComponent(textMethod)
                            .addComponent(checkBoxMethod1)
                            .addComponent(checkBoxMethod2)
                            .addComponent(checkBoxMethod3)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(textMethodI)
                                    .addComponent(textMethodK))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(valueMethodK, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
                                    .addComponent(valueMethodI, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE))))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(radioButtonT)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(sliderTime, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(radioButtonR)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(sliderR, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(textSourceData)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textThickness)
                            .addComponent(valueThickness, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textRadius)
                            .addComponent(valueRadius, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(valueBetta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textBetta))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(valueK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textK))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textC)
                            .addComponent(valueC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textAlpha)
                            .addComponent(valueAlpha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textU0)
                            .addComponent(valueU0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textTimeEnd)
                            .addComponent(valueTimeEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textP)
                            .addComponent(valueP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addComponent(textMethod)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(checkBoxMethod1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(checkBoxMethod2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(checkBoxMethod3)
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(textMethodI)
                                .addComponent(valueMethodI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(radioButtonR))
                            .addComponent(sliderR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sliderTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textMethodK)
                            .addComponent(radioButtonT)
                            .addComponent(valueMethodK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void sliderTimeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderTimeStateChanged
        // TODO add your handling code here:
        int i = sliderTime.getValue();

       // radioButtonT.setText("по t=" + Double.toString(Yavnaya.getInstance().getTk(i)));

        Draw();
    }//GEN-LAST:event_sliderTimeStateChanged

    private void sliderRStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderRStateChanged
        // TODO add your handling code here:
        int i = sliderR.getValue();

       // radioButtonR.setText("по r=" + Double.toString(Yavnaya.getInstance().getRi(i)));

        Draw();
    }//GEN-LAST:event_sliderRStateChanged

    private void radioButtonRActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioButtonRActionPerformed
        // TODO add your handling code here:
        sliderR.setEnabled(true);
        sliderTime.setEnabled(false);
        Draw();
    }//GEN-LAST:event_radioButtonRActionPerformed

    private void radioButtonTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioButtonTActionPerformed
        // TODO add your handling code here:
        sliderR.setEnabled(false);
        sliderTime.setEnabled(true);
        Draw();
    }//GEN-LAST:event_radioButtonTActionPerformed

    private void valueMethodKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_valueMethodKActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_valueMethodKActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        int newK = Integer.parseInt(valueMethodK.getText());
        int newI = Integer.parseInt(valueMethodI.getText());
        Yavnaya.getInstance().setI(newI);
        Yavnaya.getInstance().setK(newK);
        NeYavnaya.getInstance().setI(newI);
        NeYavnaya.getInstance().setK(newK);
        KrankaNikolsona.getInstance().setI(newI);
        KrankaNikolsona.getInstance().setK(newK);
        sliderR.setMinimum(0);
        sliderR.setValue(0);
        sliderR.setMaximum(newI);
        sliderTime.setMinimum(0);
        sliderTime.setValue(0);
        sliderTime.setMaximum(newK);
        Draw();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void checkBoxMethod1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBoxMethod1ActionPerformed
        Draw();
        // TODO add your handling code here:
    }//GEN-LAST:event_checkBoxMethod1ActionPerformed

    private void checkBoxMethod2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBoxMethod2ActionPerformed
        Draw();
        // TODO add your handling code here:
    }//GEN-LAST:event_checkBoxMethod2ActionPerformed

    private void checkBoxMethod3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBoxMethod3ActionPerformed
        // TODO add your handling code here:
        Draw();
    }//GEN-LAST:event_checkBoxMethod3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainForm().setVisible(true);
            }
        });
    }

    private void Draw() {
        XYSeriesCollection dataset = new XYSeriesCollection();
        JFreeChart chart = null;
        if (radioButtonR.isSelected()) {
            int i = sliderR.getValue();
            double r = Yavnaya.getInstance().getRi(i);
//            dataset.addSeries(DrawAnalyticOnR(r));
            if (checkBoxMethod1.isSelected()) {
//                dataset.addSeries(DrawMethodOnRYavnaya(i));
            }
            if (checkBoxMethod2.isSelected()) {
                dataset.addSeries(DrawMethodOnRNeYavnaya(i));
            }
            if (checkBoxMethod3.isSelected()) {
                dataset.addSeries(DrawMethodOnRKrankaNikolsona(i));
            }

            chart = ChartFactory.createXYLineChart(
                    "U(r,t) " + radioButtonR.getText() + " см", // Title
                    "t", // x-axis Label
                    "U", // y-axis Label
                    dataset, // Dataset
                    PlotOrientation.VERTICAL, // Plot Orientation
                    true, // Show Legend
                    true, // Use tooltips
                    false // Configure chart to generate URLs?
                    );
        } else {
            int k = sliderTime.getValue();
            double t = Yavnaya.getInstance().getTk(k);
//            dataset.addSeries(DrawAnalyticOnT(t));
            if (checkBoxMethod1.isSelected()) {
//                dataset.addSeries(DrawMethodOnTYavnaya(k));
            }
            if (checkBoxMethod2.isSelected()) {
                dataset.addSeries(DrawMethodOnTNeYavnaya(k));
            }
            if (checkBoxMethod3.isSelected()) {
                dataset.addSeries(DrawMethodOnTKrankaNikolsona(k));
            }

            chart = ChartFactory.createXYLineChart(
                    "U(r,t) " + radioButtonT.getText() + " c", // Title
                    "r", // x-axis Label
                    "U", // y-axis Label
                    dataset, // Dataset
                    PlotOrientation.VERTICAL, // Plot Orientation
                    true, // Show Legend
                    true, // Use tooltips
                    false // Configure chart to generate URLs?
                    );
        }

        jPanel1.removeAll();
        jPanel1.setLayout(new java.awt.BorderLayout());
        ChartPanel CP = new ChartPanel(chart);
        jPanel1.add(CP, BorderLayout.CENTER);
        jPanel1.validate();

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupFixed;
    private javax.swing.ButtonGroup buttonGroupMethod;
    private javax.swing.JCheckBox checkBoxMethod1;
    private javax.swing.JCheckBox checkBoxMethod2;
    private javax.swing.JCheckBox checkBoxMethod3;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton radioButtonR;
    private javax.swing.JRadioButton radioButtonT;
    private javax.swing.JSlider sliderR;
    private javax.swing.JSlider sliderTime;
    private javax.swing.JLabel textAlpha;
    private javax.swing.JLabel textBetta;
    private javax.swing.JLabel textC;
    private javax.swing.JLabel textK;
    private javax.swing.JLabel textMethod;
    private javax.swing.JLabel textMethodI;
    private javax.swing.JLabel textMethodK;
    private javax.swing.JLabel textP;
    private javax.swing.JLabel textRadius;
    private javax.swing.JLabel textSourceData;
    private javax.swing.JLabel textThickness;
    private javax.swing.JLabel textTimeEnd;
    private javax.swing.JLabel textU0;
    private javax.swing.JTextField valueAlpha;
    private javax.swing.JTextField valueBetta;
    private javax.swing.JTextField valueC;
    private javax.swing.JTextField valueK;
    private javax.swing.JTextField valueMethodI;
    private javax.swing.JTextField valueMethodK;
    private javax.swing.JTextField valueP;
    private javax.swing.JTextField valueRadius;
    private javax.swing.JTextField valueThickness;
    private javax.swing.JTextField valueTimeEnd;
    private javax.swing.JTextField valueU0;
    // End of variables declaration//GEN-END:variables

//private XYSeries DrawAnalyticOnR(double r) {
//        XYSeries series = new XYSeries("Аналитическое решение");
//        double eps = 1;
//
//
//        double val = 0;
//        while (!(val >= Constants.getTimeEnd()+eps)) {
//            try {
//                //double temp=Constants.getU0()-Analytic.getValueAt(4, val, eps);
//                double temp=0;
//                series.add(val, Analytic.getValueAt(r, val, eps)+temp);
//            } catch (Exception ex) {
//            }
//            val += eps;
//        }
//
//        return series;
//
//    }
//
//    private XYSeries DrawAnalyticOnT(double t) {
//        XYSeries series = new XYSeries("Аналитическое решение");
//        double eps = 0.01;
//
//        double val = 0;
//        while (!(val >= Constants.getRadius()+eps)) {
//            try {
//                //double temp=Constants.getU0()- Analytic.getValueAt(4, t, eps);
//                double temp=0;
//                series.add(val, Analytic.getValueAt(val, t, eps)+temp);
//            } catch (Exception ex) {
//            }
//            val += eps;
//        }
//
//        return series;
//
//    }

//    private XYSeries DrawMethodOnRYavnaya(int i) {
//        XYSeries series = null;
//        series = new XYSeries("Явная разностная схема");
//        for (int k = 0; k <= Yavnaya.getInstance().getK(); k++) {
//            series.add(Yavnaya.getInstance().getTk(k), Yavnaya.getInstance().getValueAt(k, i));
//        }
//        return series;
//    }
//
//    private XYSeries DrawMethodOnTYavnaya(int k) {
//        XYSeries series = null;
//        series = new XYSeries("Явная разностная схема");
//        for (int i = 0; i <= Yavnaya.getInstance().getI(); i++) {
//            series.add(Yavnaya.getInstance().getRi(i), Yavnaya.getInstance().getValueAt(k, i));
//        }
//        return series;
//    }

    private XYSeries DrawMethodOnRNeYavnaya(int i) {
        XYSeries series = null;
        series = new XYSeries("Неявная разностная схема");
        for (int k = 0; k <= NeYavnaya.getInstance().getK(); k++) {
            series.add(NeYavnaya.getInstance().getTk(k), NeYavnaya.getInstance().getValueAt(k, i));
        }
        return series;
    }

    private XYSeries DrawMethodOnTNeYavnaya(int k) {
        XYSeries series = null;
        series = new XYSeries("Неявная разностная схема");
        for (int i = 0; i <= NeYavnaya.getInstance().getI(); i++) {
            series.add(NeYavnaya.getInstance().getRi(i), NeYavnaya.getInstance().getValueAt(k, i));
        }
        return series;
    }

    private XYSeries DrawMethodOnRKrankaNikolsona(int i) {
        XYSeries series = null;
        series = new XYSeries("Разностная схема Кранка-Николсона");
        for (int k = 0; k <= KrankaNikolsona.getInstance().getK(); k++) {
            series.add(KrankaNikolsona.getInstance().getTk(k), KrankaNikolsona.getInstance().getValueAt(k, i));
        }
        return series;
    }

    private XYSeries DrawMethodOnTKrankaNikolsona(int k) {
        XYSeries series = null;
        series = new XYSeries("Разностная схема Кранка-Николсона");
        for (int i = 0; i <= KrankaNikolsona.getInstance().getI(); i++) {
            series.add(KrankaNikolsona.getInstance().getRi(i), KrankaNikolsona.getInstance().getValueAt(k, i));
        }
        return series;
    }
}
